package com.zyj.test.month1.day7;

/**
 * @author Yijia Zhang
 * @create 2024-04-28 22:29
 */
public class code1017 {
    public String baseNeg2(int n) {
        if (n == 0) {
            return "0";
        }
        int maxVal = 0x55555555;
        int a = maxVal ^ (maxVal - n);
        //将a转化成二进制
        StringBuilder sb = new StringBuilder();
        while (a > 0) {
            if (a % 2 == 0) {
                sb.append(0);
            } else {
                sb.append(1);
            }
            a /= 2;
        }
        return sb.reverse().toString();
    }
}
